package br.ucb.rest.controle.servlet.impl;

import java.util.Date;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.ucb.rest.controle.servlet.AbstractServlet;
import br.ucb.rest.negocio.impl.FilaChamadoBOS;
import br.ucb.rest.negocio.impl.GarcomBOS;
import br.ucb.rest.negocio.impl.MesaBOS;
import br.ucb.rest.persistencia.vo.FilaChamadoVO;
import br.ucb.rest.util.Constantes;
import br.ucb.rest.util.MensagemUtil;

@WebServlet(urlPatterns={"/geral"})
public class GeralServlet extends AbstractServlet {
	
	public GeralServlet() {
		super();
	}
	
	public void chamarGarcom(HttpServletRequest request, HttpServletResponse response) {
		try {
			String codigoGarcom = request.getParameter("codigoGarcom");
			String numeroMesa = request.getParameter("numeroMesa");
			
			
			FilaChamadoVO vo = new FilaChamadoVO();
			vo.setDtChamado(new Date(System.currentTimeMillis()));
			
			vo.setGarcomVO(GarcomBOS.getInstance().recuperarPorNumeroGarcom(Integer.valueOf(codigoGarcom)));
			vo.setInAtendido(Boolean.FALSE);
			vo.setMesaVO(MesaBOS.getInstance().recuperarPorNumeroMesa(Integer.valueOf(numeroMesa)));
			vo.setTxMotivo(MensagemUtil.getInstance().getMensgem(Constantes.CHAMADA_NORMAL));
			
			
			FilaChamadoBOS.getInstance().incluirChamado(vo);
			
			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void recuperarNomeGarcom(HttpServletRequest request, HttpServletResponse response) {
		try {
			String numeroGarcom = request.getParameter("codigoGarcom");
			
			String nome = GarcomBOS.getInstance().recuperarNome(Integer.valueOf(numeroGarcom));
			
			response.getOutputStream().write(nome.getBytes());
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

}
